package com.wjk.test;

/**
 * @author : RobertWei
 * time: 2021/9/23    21:39
 * description:
 */

public class Demo {

    public void moveZeroes(int[] nums) {

        for (int i = 0; i < nums.length - 1; i++) {
            // 出现 0 将当前数与下一个非 0 数调换位置
            if (nums[i] == 0) {
                nums[i] = change(nums, i);
            }
        }
    }

    public int change(int[] nums, int i) {

        int tem = 0;
        //如果下一位仍为 0 则递归调用
        if (nums[i + 1] == 0 && ( i + 1) < nums.length) {
            return change(nums, i + 1);
        }
        //不为 0 交换位置
        tem = nums[i + 1];
        nums[i + 1] = 0;
        return tem;

    }
}
